<?php

namespace falcon5\inc\Infrastructure\Services;

use falcon5\inc\Base\LanguageAutoSwitch;
use falcon5\inc\Base\WPOption;
use hollisho\helpers\ArrayHelper;
use hollisho\helpers\InvalidArgumentException;
use lucatume\DI52\ContainerException;

/**
 * Class SiteService
 * @package falcon5\inc\Infrastructure\Services
 * @desc site service
 */
class SiteService
{
    /**
     * update site info
     * @param array $siteInfo
     * @return void
     * @throws ContainerException
     * @throws InvalidArgumentException
     */
    public function updateSite(array $siteInfo)
    {
        $autoSwitch = ArrayHelper::getValue($siteInfo, 'auto_switch');

        if ($autoSwitch) {
            $option = falcon5_app(LanguageAutoSwitch::class);
            $option->setAutoSwitch($autoSwitch);
        }
    }


    /**
     * delete site
     * @param array $siteInfo
     * @return void
     * @throws ContainerException
     * @throws InvalidArgumentException
     */
    public function delSite(array $siteInfo)
    {
        $apiKey = ArrayHelper::getValue($siteInfo, 'api_key');
        /** @var WPOption $falcon5Option */
        $falcon5Option = falcon5_app(WPOption::class);
        /** @var CacheService $cacheService */
        $cacheService = falcon5_app(CacheService::class);
        if ($apiKey && $apiKey === $falcon5Option->getApiKey()) {
            $cacheService->delAllCache();
        }
    }
}